import React, { Component, PropTypes } from "react";
import { messages } from "share/common";
import { Modal, Button, message } from 'antd'
import borrowService from "../../borrow-and-return.service";

class BtnDelete extends Component {

  state = {
    loading: false
  };

  handleConfirm = () => {
    Modal.confirm({
      title: messages('finance-1.key102')/*删除单据*/,
      content: messages('finance-1.key103')/*确定删除该单据？*/,
      okText: messages('common.ok')/*确定*/,
      onOk: this.handleDelete
    })
  };

  handleDelete = () => {
    const { info, close } = this.context;
    this.setState({ loading: true });
    borrowService.deleteRequest(info.loanBillOID).then(() => {
      this.setState({ loading: false });
      message.success(messages('common.delete.success',{arg1: ''})/*{arg1} 删除成功*/);
      close(true);
    }).catch(() => {
      this.setState({ loading: false });
      message.error(messages('common.operate.filed')/*操作失败*/)
    })
  };

  render() {
    const { loading } = this.state;
    return (
      <Button
        style={{ color: '#fff', backgroundColor: '#ff4d4f', borderColor: '#ff4d4f' }}
        loading={loading}
        onClick={this.handleConfirm}
      >
        {messages('finance-1.key102')/*删除单据*/}
      </Button>
    )
  }

  static contextTypes = {
    info: PropTypes.object,
    close: PropTypes.func
  }

}

export default BtnDelete
